<template>
<div>
  <div style="position: sticky;top:0;left:0;z-index: 9999">
    <van-nav-bar :title="'购物车'+'('+num+')'">
    </van-nav-bar>
  </div>
  <van-swipe-cell v-for="(item,index) in list" :key="index">
    <van-checkbox v-model="item.is_promote" @change="setVuex(item.is_promote,index)">{{"商品ID:"+item.goods_id}}</van-checkbox>
    <van-card
        :num="item.num"
        :price="item.goods_price"
        desc="测试数据"
        :title="item.goods_name"
        class="goods-card"
        :thumb="item.goods_big_logo"
    />
    <template #right>
      <van-button square text="删除" type="danger" class="delete-button" />
    </template>
  </van-swipe-cell>

  <van-submit-bar style="margin-bottom: 60px" :price="Allmoney*100" button-text="提交订单" @submit="onSubmit">
    <van-checkbox v-model="ckAll" @click="setAll(ckAll)">全选</van-checkbox>
    <template #tip>
      你的收货地址不支持配送, <span @click="onClickLink">修改地址</span>
    </template>
  </van-submit-bar>

</div>
</template>

<script>
import {toRefs}from 'vue'
import {useStore}from 'vuex'
export default {
name: "cart",
  setup(){
    const store=useStore()
    const data=store.state.details
    console.log(data)
    //设置全选
    const setAll=(bool)=>{
      store.commit('details/setAllchange',bool)
    }
    //单选
    const setVuex=(bool,index)=>{
      let obj={bool,index}
      store.commit('details/setckange',obj)
    }

    const onSubmit = () =>{
      console.log(1)};
    const onClickLink = () =>{
      console.log(1)
    };
      return{
        setVuex,
        onSubmit,
        setAll,
        onClickLink,
          ...toRefs(data),
      }
  },
}
</script>

<style scoped lang="less">
.goods-card {
  margin: 0;
  background-color:white;
}

.delete-button {
  height: 100%;
}
</style>